package com.wn.controller;

import com.wn.bean.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author yellow Docter
 * @date 2022 -07-11
 * @desc
 */
@Controller
@RequestMapping("/user")
public class UserController {

    @ResponseBody       // 不加 回去 找 view 如果加了返回的是json字符串
    @RequestMapping("/save")
    public String save(){
        System.out.println("UserController.save");
        return "{'info':'springmvc'}";
    }

    /**
     * 接收参数:
     *    直接使用变量接受我们的 前端发送过来的数据
     *    变量的名称和前端的发送过来的 数据key 需要一致
     *
     *    @RequestParam("name") 从前端获取数据, 赋值给变量 userName
     * @return
     */
    @ResponseBody
    @RequestMapping("/data1")
    public String data1(@RequestParam("name") String userName, Integer age){

        System.out.println("name = " + userName);
        System.out.println("age = " + age);

        return "{'info':'springmvc'}";
    }

    @ResponseBody
    @RequestMapping("/data2")
    public String data2(User user){

        System.out.println("UserController.user " + user);

        return "{'info':'springmvc'}";
    }

    @ResponseBody
    @RequestMapping("/data3")
    public String data3(String [] favs){
        System.out.println("UserController.data3" + Arrays.toString(favs));
        return "{'info':'springmvc'}";
    }

    @ResponseBody
    @RequestMapping("/data4")
    public String data4(@RequestParam List<String> favs){

        ArrayList arrayList;
        System.out.println("UserController.data4" + favs);
        return "{'info':'springmvc'}";
    }

}
